# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libbluray
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.4
pkgrel=1
pkgdesc="Library to access Blu-Ray disks for video playback (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://www.videolan.org/developers/libbluray.html'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://download.videolan.org/pub/videolan/libbluray/${pkgver}/${_realname}-${pkgver}.tar.bz2)
sha256sums=('478ffd68a0f5dde8ef6ca989b7f035b5a0a22c599142e5cd3ff7b03bbebe5f2b')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
}

build() {
  export lt_cv_deplibs_check_method='pass_all'

  [[ -d "${srcdir}/build-static-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-static-${MSYSTEM}"
  mkdir -p "${srcdir}/build-static-${MSYSTEM}" && cd "${srcdir}/build-static-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-examples \
    --disable-bdjava-jar \
    --enable-shared=no \
    --enable-static=yes \
    LIBXML2_CFLAGS="$(xml2-config --cflags) -DLIBXML_STATIC" \
    LIBXML2_LIBS="$(xml2-config --libs)"

    make

  [[ -d "${srcdir}/build-shared-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-shared-${MSYSTEM}"
  mkdir -p "${srcdir}/build-shared-${MSYSTEM}" && cd "${srcdir}/build-shared-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-examples \
    --disable-bdjava-jar \
    --enable-shared=yes \
    --enable-static=no

    make
}

package() {
  cd "${srcdir}/build-static-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/build-shared-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  local _prefix_win="$(cygpath -m "${MINGW_PREFIX}")"
  sed -s "s|${_prefix_win}|${MINGW_PREFIX}|g" -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libbluray.pc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
